package com.yanqu.road.server.cmd.cookboy.process2;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.cookboy.CrossCookBoyMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


@Cmd(code = Protocol.C_CROSS_COOK_BOY2_SERVE_DISH, desc = "小当家第一阶段上食材")
public class CrossServeDishCmd extends CrossCommand {

    private long userId;
    private int activityId;
    //id dishId
    private Map<Integer,Integer> dishMap = new ConcurrentHashMap<>();
    private UserBaseInfo userBaseInfo;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CookBoyProto.CrossCookBoyServeDishReqMsg reqMsg = CookBoyProto.CrossCookBoyServeDishReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        activityId = reqMsg.getActivityId();
        for(CookBoyProto.CrossCookBoyServeDishInfoMsg tempMsg : reqMsg.getDishListList()){
            dishMap.put(tempMsg.getId(),tempMsg.getDishId());
        }
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerBaseData());
        CrossUserMgr.updateUserBaseInfo(userId,userBaseInfo);
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossCookBoyMgr.serveDish(activityId,serverId,userId,dishMap);
    }

    @Override
    public void sendData() {

    }

}
